// src/tim.js
import TIM from 'tim-js-sdk';
import TIMUploadPlugin from 'tim-upload-plugin';

// 获取 SDKAppID
const SDKAppID = import.meta.env.VITE_SDKAPPID;

if (!SDKAppID) {
  throw new Error('VITE_SDKAPPID is not defined in environment variables');
}

// 创建 SDK 实例
const tim = TIM.create({
  SDKAppID: Number(SDKAppID)
});

// 检查 tim 实例是否创建成功
if (!tim) {
  throw new Error('Failed to create TIM instance');
}

// 注册上传插件
tim.registerPlugin({ 'tim-upload-plugin': TIMUploadPlugin });

// 设置日志级别
tim.setLogLevel(0);

export { tim, TIM };
